package com.huidu.bitrade.task;

import com.huidu.bitrade.service.AcMemberService;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;

@Component("HdcAwardTask")
@RequiredArgsConstructor
public class HdcAwardTask {

    private final Logger log = LoggerFactory.getLogger("member-task");

    private final AcMemberService acMemberService;
    @Value("${award.hdc}")
    private Integer isFlag;

    /**
     *  每天凌晨一点执行一次
     *  前一天推荐手续费奖励发放
     * */
    @Scheduled(cron = "0 0 1 * * *",zone = "Asia/Shanghai")
    public void chargeAwardGrant(){
        log.info("========推荐手续费奖励发放任务触发==========");
        log.info("========东八区时间：{}========", LocalDateTime.now(ZoneId.of("+8")));
        log.info("========UTC时间：{}========", LocalDateTime.now(ZoneOffset.UTC));
        if(isFlag==1){
            log.info("=============推荐手续费奖励发放任务触发执行============");
            acMemberService.chargeAwardGrant(null);
            log.info("=============推荐手续费奖励发放任务执行结束============");
        }
    }

    /**
     *  每天凌晨两点执行一次
     *  发放hdc奖励
     * */
    @Scheduled(cron = "0 0 2 * * *",zone = "Asia/Shanghai")
    public void hdcAward(){
        log.info("========发放hdc奖励触发==========");
        log.info("========东八区时间：{}========", LocalDateTime.now(ZoneId.of("+8")));
        log.info("========UTC时间：{}========", LocalDateTime.now(ZoneOffset.UTC));
        if(isFlag==1){
            log.info("=============发放hdc奖励执行============");
            acMemberService.hdcAward();
            log.info("=============发放hdc奖励执行结束============");
        }
    }

    /**
     *  每个月十五号凌晨三点执行
     *  发放上月交易手续费奖励（hdc）
     * */
    @Scheduled(cron = "0 0 3 15 * ?",zone = "Asia/Shanghai")
    public void chargeHdcAward(){
        log.info("========发放上月交易手续费奖励（hdc）触发==========");
        log.info("========东八区时间：{}========", LocalDateTime.now(ZoneId.of("+8")));
        log.info("========UTC时间：{}========", LocalDateTime.now(ZoneOffset.UTC));
        if(isFlag==1){
            log.info("=============发放上月交易手续费奖励（hdc）触发执行============");
            acMemberService.chargeHdcAward();
            log.info("=============发放上月交易手续费奖励（hdc）执行结束============");
        }
    }

}
